<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>员工添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <!-- 头部区域 -->
        <div class="layui-header">
            <div class="layui-logo layui-hide-xs layui-bg-black">小药店管理系统</div>
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                    <a href="javascript:;">
                        <img src="//unpkg.com/outeres@0.0.10/img/layui/icon-v2.png" class="layui-nav-img">
                        欢迎, <span id="username">管理员</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" onclick="logout()">退出</a></dd>
                    </dl>
                </li>
            </ul>
        </div>

        <!-- 左侧导航区域 -->
        <div class="layui-side layui-bg-black">
            <div class="layui-side-scroll">
                <ul class="layui-nav layui-nav-tree" lay-filter="test">
                    <li class="layui-nav-item">
                        <a href="javascript:;">采购管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="../supplier/supplier.html">供应商信息管理</a></dd>
                            <dd><a href="../supplier/drug.html">药品信息管理</a></dd>
                            <dd><a href="../procurement/add.html">采购单添加</a></dd>
                            <dd><a href="../procurement/list.html">采购单管理</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item">
                        <a href="javascript:;">销售管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="../sales/add_xiaoshoudan.html">销售单添加</a></dd>
                            <dd><a href="../sales/xiaoshoumingxi.html">销售单管理</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item">
                        <a href="javascript:;">药店统计管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="../statistics/instock.html">入库统计</a></dd>
                            <dd><a href="../statistics/sales.html">销售统计</a></dd>
                            <dd><a href="../statistics/stock.html">库存查询</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item layui-nav-itemed">
                        <a href="javascript:;">人事管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="add_yuangong.html">员工添加</a></dd>
                            <dd><a href="yuangong.html">员工管理</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item">
                        <a href="javascript:;">打印管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="../print/ruku.html">入库单</a></dd>
                            <dd><a href="../print/chuku.html">出库单</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item">
                        <a href="javascript:;">系统管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="../user/xiuGaiMiMa.html">修改密码</a></dd>
                        </dl>
                    </li>
                </ul>
            </div>
        </div>

        <!-- 内容主体区域 -->
        <div class="layui-body">
            <div style="padding: 15px;">
                <!-- 面包屑导航 -->
                <div class="layui-card">
                    <div class="layui-card-body">
                        <span class="layui-breadcrumb">
                            <a href="../index.html">首页</a>
                            <a href="yuangong.html">员工管理</a>
                            <a><cite>添加员工</cite></a>
                        </span>
                    </div>
                </div>

                <!-- 添加员工表单 -->
                <div class="layui-card">
                    <div class="layui-card-header">添加员工信息</div>
                    <div class="layui-card-body">
                        <form class="layui-form" lay-filter="employeeForm">
                            <div class="layui-form-item">
                                <label class="layui-form-label">姓名</label>
                                <div class="layui-input-block">
                                    <input type="text" name="name" required lay-verify="required" 
                                           placeholder="请输入姓名" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">性别</label>
                                <div class="layui-input-block">
                                    <input type="radio" name="sex" value="男" title="男" checked>
                                    <input type="radio" name="sex" value="女" title="女">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">年龄</label>
                                <div class="layui-input-block">
                                    <input type="number" name="age" required lay-verify="required|number" 
                                           placeholder="请输入年龄" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">电话</label>
                                <div class="layui-input-block">
                                    <input type="text" name="tel" required lay-verify="required|phone" 
                                           placeholder="请输入电话" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">地址</label>
                                <div class="layui-input-block">
                                    <input type="text" name="address" required lay-verify="required" 
                                           placeholder="请输入地址" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">职位</label>
                                <div class="layui-input-block">
                                    <select name="position" lay-verify="required">
                                        <option value="">请选择职位</option>
                                        <option value="店长">店长</option>
                                        <option value="销售员">销售员</option>
                                        <option value="采购员">采购员</option>
                                        <option value="仓管员">仓管员</option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="employeeForm">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="/layui/layui.js"></script>
    <script>
        layui.use(['form', 'layer'], function(){
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.jquery;

            // 表单提交
            form.on('submit(employeeForm)', function(data){
                var formData = data.field;
                
                $.ajax({
                    url: '/employee/add',
                    type: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify(formData),
                    success: function(res){
                        if(res.code === 0){
                            layer.msg('添加成功', {
                                icon: 1,
                                time: 2000
                            }, function(){
                                window.location.href = 'yuangong.html';
                            });
                        } else {
                            layer.msg(res.msg || '添加失败', {icon: 2});
                        }
                    }
                });
                return false;
            });
        });

        // 退出登录
        function logout() {
            layui.use(['jquery', 'layer'], function(){
                var $ = layui.$;
                var layer = layui.layer;
                
                $.ajax({
                    url: '/user/logout',
                    type: 'GET',
                    success: function(res) {
                        if(res.code === 0) {
                            window.location.href = '/login/login.html';
                        } else {
                            layer.msg(res.msg || '退出失败', {icon: 2});
                        }
                    },
                    error: function() {
                        layer.msg('服务器错误', {icon: 2});
                    }
                });
            });
        }
    </script>
</body>
</html>